package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author xioayang
 * @since 2024-06-25
 */
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
@Api(tags = {"互动问答-用户端-问题相关接口"})
public class InteractionQuestionController {
    private final IInteractionQuestionService questionService;

    /**
     * 1、新增互动问题
     * @param questionDTO
     */
    @ApiOperation("新增互动问题")
    @PostMapping
    public void saveQuestion(@Valid @RequestBody QuestionFormDTO questionDTO){
        questionService.saveQuestion(questionDTO);
    }

    /**
     * 2、分页查询互动问题
     * @param query
     */
    @ApiOperation("分页查询互动问题")
    @GetMapping("/page")
    public PageDTO<QuestionVO> queryQuestionPageList(@Validated QuestionPageQuery query){
        return questionService.queryQuestionPageList(query);
    }

    /**
     * 3、根据ID查询互动问题
     * @param id 问题ID
     */
    @ApiOperation("根据ID查询互动问题")
    @GetMapping("/{id}")
    public QuestionVO queryById(@PathVariable("id") Long id){
        return questionService.queryById(id);
    }


    /**
     * 4、修改互动问题
     * @param query
     * @param id
     */
    @ApiOperation("修改互动问题")
    @PutMapping("/{id}")
    public void updateQuestion(@Valid @RequestBody QuestionFormDTO query, @PathVariable("id") Long id){
        questionService.updateQuestion(query,id);
    }

    /**
    * 5、根据ID删除互动问题（Day5 - 实战）
    * @param id
    */
    @ApiOperation("根据ID删除互动问题")
    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") Long id){
        questionService.deleteById(id);
    }



}
